package sz.szsmk.citizencard.mvp.presenter;

import javax.inject.Inject;

import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.model.network.bean.request.LoginRequest;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CheckSmsReponse;
import sz.szsmk.citizencard.mvp.LoginByMessageMvpView;
import sz.szsmk.citizencard.mvp.dzsmkpresenter.AppBasePresenter;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.util.AndroidUtils;

/**
 * author : hyt
 * date : 2019/8/29
 * description :
 */
public class LoginByMessagePresenter extends AppBasePresenter<LoginByMessageMvpView> {
    private NetworkDateSources mNetworkDateSource;

    @Inject
    public LoginByMessagePresenter() {
        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }

    public void sendMessage(String phonenumber){
        LoginRequest loginRequest = new LoginRequest();
        loginRequest.setChannel_id( AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        loginRequest.setMobile(phonenumber);
        loginRequest.setIp("");
        mNetworkDateSource.sendSmsCode(loginRequest, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                getMvpView().sendMessage(response);
            }

            @Override
            protected void onFailure(BaseBean response) {
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    public void checkCheckSmsCode(String phonenumber,String sms_code){
        LoginRequest loginRequest = new LoginRequest();
        loginRequest.setDevice_id( AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        loginRequest.setMobile(phonenumber);
        loginRequest.setSms_code(sms_code);

        mNetworkDateSource.checkCheckSmsCode(loginRequest, new SubscribeResult<CheckSmsReponse>() {
            @Override
            protected void onOk(CheckSmsReponse response) {
                getMvpView().checkSmsCodeResult(response);
            }

            @Override
            protected void onFailure(CheckSmsReponse response) {
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });

    }

}
